package com.swust.monitorProject.service.impl;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swust.monitorProject.dto.UserDto;
import com.swust.monitorProject.entity.Dept;
import com.swust.monitorProject.entity.QUser;
import com.swust.monitorProject.mapper.DeptMapper;
import com.swust.monitorProject.service.IDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
 * 部门服务实现类
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService{

    @Autowired
    private DeptMapper deptMapper;
    @Override
    public IPage<UserDto> pageUser(Page page, QUser qUser) {
        return baseMapper.pageUser(page, qUser);
    }

    @Override
    public Boolean updateDeptCata(Long deptId, String newCata) {
        Dept dept = new Dept();
        dept.setDeptId(Math.toIntExact(deptId)); // 修改后可以接受 Long 类型
        dept.setDeptName(newCata); // 假设字段名为 deptName 而不是 cata

        UpdateWrapper<Dept> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("dept_id", deptId); // 假设数据库中 dept_id 的列名为 dept_id

        return deptMapper.update(dept, updateWrapper) > 0;
    }
    @Override
    public Boolean createDept(Dept dept) {
        // 插入新部门
        if (deptMapper.insert(dept) != 1) {
            return false; // 插入失败
        }
        return true; // 插入成功
    }
}

